﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Nuane.Posterous
{

	/// <summary>
	/// Posterous error status.
	/// </summary>
	public enum PosterousExceptionStatus
	{
		/// <summary>
		/// An unclassifiable error occurred. This is the default value for <see cref="PosterousException.Status"/>.
		/// </summary>
		UnclassifiableError = 0,

		/// <summary>
		/// The requested operation could not be completed.
		/// </summary>
		OperationFailure = 1,

		/// <summary>
		/// The response received from the server was complete but indicated a protocol-level error.
		/// </summary>
		ProtocolError = 2,

		/// <summary>
		/// The server response was not a valid response.
		/// </summary>
		ServerProtocolViolation = 3,

		/// <summary>
		/// Error at the HTTP level.
		/// </summary>
		HttpError = 4,
	}


	/// <summary>
	/// Represents a posterous error.
	/// </summary>
	public class PosterousException : Exception
	{
		/// <summary>
		/// Gets posterous error code, or 0 if not available.
		/// </summary>
		/// <value>Posterous error code.</value>
		public int ErrorCode { get; private set; }

		/// <summary>
		/// Gets error status.
		/// </summary>
		/// <value>Error status.</value>
		public PosterousExceptionStatus Status { get; private set; }

		/// <summary>
		/// Creates a new instance of <see cref="PosterousException"/>.
		/// </summary>
		/// <param name="message">Error message.</param>
		public PosterousException(string message)
			: this(message, PosterousExceptionStatus.UnclassifiableError, 0)
		{
		}

		/// <summary>
		/// Creates a new instance of <see cref="PosterousException"/>.
		/// </summary>
		/// <param name="message">Error message.</param>
		/// <param name="status">Error status.</param>
		public PosterousException(string message, PosterousExceptionStatus status)
			: this(message, status, 0)
		{
		}

		/// <summary>
		/// Creates a new instance of <see cref="PosterousException"/>.
		/// </summary>
		/// <param name="message">Error message.</param>
		/// <param name="status">Error status.</param>
		/// <param name="innerException">The exception that is the cause of this exception, or null if not specified.</param>
		public PosterousException(string message, PosterousExceptionStatus status, Exception innerException)
			: base(message, innerException)
		{
			Status = status;
		}

		/// <summary>
		/// Creates a new instance of <see cref="PosterousException"/>.
		/// </summary>
		/// <param name="message">Error message.</param>
		/// <param name="status">Error status.</param>
		/// <param name="errorCode">Error code.</param>
		public PosterousException(string message, PosterousExceptionStatus status, int errorCode)
			: base(message)
		{
			ErrorCode = errorCode;
			Status = status;
		}
	}
}
